;
(function () {
  'use strict';
  angular.module('services.analysisSysOM.responseTime')
    .service('realTimeService', realTimeService);

  function realTimeService($http, $filter, socketServer, $rootScope) {
    this.maxResponseTime = null;
    this.minResponseTime = null;
    this.avgResponseTime = null;
    var that = this;
    this.loding = true;
    this.initSelectData = function () {
      that.loding = true;
      $http.get('/sas/analysisSysOM/sysPerformance/responsetime/showRealTimeData/query')
        .then(function (res) {
          that.loding = false;
          //console.log(res);
          if (res.data.state === '10000') {
            that.maxResponseTime = res.data.data.maxResponseTime || 0;
            that.minResponseTime = res.data.data.minResponseTime || 0;
            that.avgResponseTime = res.data.data.avgResponseTime || 0;
            onSocket();
          }
        }, function (res) {
          //console.log('111');
        }
      );
    };


    function onSocket() {
      socketServer.socket.on('realTimeRes', function (res) {
        try {
          that.maxResponseTime = res.maxResponseTime || 0;
          that.minResponseTime = res.minResponseTime || 0;
          that.avgResponseTime = res.avgResponseTime || 0;
          $rootScope.$digest();
          //console.log('socket realTimeRes...');
        } catch (e) {
          alert(e.name + ": " + e.message);
        }
      });
    }

  }

  realTimeService.$inject = ['$http', '$filter', 'socketServer', '$rootScope'];


})();